package com.topscomm.center;

import com.topscomm.basic.exception.ServiceException;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.tap.TapEntity;
import com.topscomm.tap.TapService;
import com.topscomm.tap.common.SessionUserBean;

@SuppressWarnings("rawtypes")
public class CenterService<T extends CenterEntity, TDao extends ICenterDao> extends TapService<T, TDao>
		implements ICenterService<T, TDao> {
	/**
	 * 统一的给扩充字段赋值，第一个为单号，第二个为申请部门，第三个位申请人
	 */
	@Override
	protected void afterSubmit(TapEntity entity, SessionUserBean sessionUserBean) {
		super.afterSubmit(entity, sessionUserBean);
		try {
			StringBufferProxy sql = new StringBufferProxy();
			sql.appendLineSingle("update CboApprovalFlowIns set ");
			sql.appendLineSingle("extendfield1 = (select docno from {0} "
					+ "where CboApprovalFlowIns.sourceid = {0}.id " + "and CboApprovalFlowIns.sourcetype = '{0}'),",
					entity.getTableName());
			sql.appendLineSingle("extendfield2 = (select deptcode from {0} "
					+ "where CboApprovalFlowIns.sourceid = {0}.id " + "and CboApprovalFlowIns.sourcetype = '{0}'),",
					entity.getTableName());
			sql.appendLineSingle("extendfield3 = (select usercode from {0} "
					+ "where CboApprovalFlowIns.sourceid = {0}.id " + "and CboApprovalFlowIns.sourcetype = '{0}')",
					entity.getTableName());
			sql.appendLineSingle("where sourceid = '{0}' and sourcetype='{1}'", entity.getId(), entity.getTableName());

			this.getDao().updateExecute(sql.toString());
		} catch (Exception e) {
			throw new ServiceException(e);
		}
	}

}